import {formatStaticUrl} from "@/utils/domain";

export const previewPic = (url: string) => {
    if (isImageUrlByExtension(url)) {
        if (!url.includes("http")) {
            url = formatStaticUrl(url)
        }
        uni.previewImage({
            urls: [url]
        })
    } else {
        console.log("跳转 -- console.log");
        window.open(url);
    }
}


export const previewPics = (urls: string[]) => {
    uni.previewImage({
        urls: urls
    })
}


function isImageUrlByExtension(filename: string): boolean {
    const imageExtensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".dib", ".jfif", ".tiff", ".webp", ".ico"]; // 添加更多图片格式如果需要
    filename = filename.split("?")[0];
    const extensionMatch = filename.match(/\.\w+$/i);
    if (!extensionMatch) {
        return false;
    }

    const extension = extensionMatch[0].toLowerCase();
    return imageExtensions.includes(extension);
}